package com.wcpdoc.survey.survey.entity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.wcpdoc.survey.sys.cache.DictCache;

/**
 * 问题实体扩展
 * 
 * v1.0 zhanghc 2017-05-07 14:56:29
 */
public class QuestionEx extends Question {
	private List<QuestionOption> rowOptionList;
	private List<QuestionOption> colOptionList;
	private List<QuestionOption> selectOptionList;
	private List<String> allIndexList;

	public QuestionEx(Question question) {
		BeanUtils.copyProperties(question, this);

		if (getType() >= 1 && getType() <= 8) {
			String[] optionAs = getOptionA().split("\r\n");
			rowOptionList = new ArrayList<>();
			for (int i = 0; i < optionAs.length; i++) {
				String dictValue = DictCache.getDictValue("QUESTION_OPTIONS", (i + 1) + "");
				QuestionOption questionExOption = new QuestionOption();
				questionExOption.setIndex(dictValue);
				questionExOption.setName(optionAs[i]);
				rowOptionList.add(questionExOption);
			}

			if (getType() == 3 || getType() == 6 || getType() == 8) {
				String[] optionBs = getOptionB().split("\r\n");
				colOptionList = new ArrayList<>();
				for (int i = 0; i < optionBs.length; i++) {
					String dictValue = DictCache.getDictValue("QUESTION_OPTIONS", (i + 1) + "");
					QuestionOption questionExOption = new QuestionOption();
					questionExOption.setIndex(dictValue);
					questionExOption.setName(optionBs[i]);
					colOptionList.add(questionExOption);
				}

				if (getType() == 8) {
					String[] optionCs = getOptionC().split("\r\n");
					selectOptionList = new ArrayList<>();
					for (int i = 0; i < optionCs.length; i++) {
						String dictValue = DictCache.getDictValue("QUESTION_OPTIONS", (i + 1) + "");
						QuestionOption questionExOption = new QuestionOption();
						questionExOption.setIndex(dictValue);
						questionExOption.setName(optionCs[i]);
						selectOptionList.add(questionExOption);
					}
				}
			}

			allIndexList = new ArrayList<>();
			if (getType() == 1 || getType() == 2 || getType() == 4 || getType() == 5 || getType() == 7) {
				for (QuestionOption row : rowOptionList) {
					allIndexList.add(row.getIndex());
				}
			} else if (getType() == 3 || getType() == 6) {
				for (QuestionOption row : rowOptionList) {
					for (QuestionOption col : colOptionList) {
						allIndexList.add(row.getIndex() + col.getIndex());
					}
				}
			} else if (getType() == 8) {
				for (QuestionOption row : rowOptionList) {
					for (QuestionOption col : colOptionList) {
						for (QuestionOption select : selectOptionList) {
							allIndexList.add(row.getIndex() + col.getIndex() + select.getIndex());
						}
					}
				}
			}
		}
	}

	public List<QuestionOption> getRowOptionList() {
		return rowOptionList;
	}

	public List<QuestionOption> getColOptionList() {
		return colOptionList;
	}

	public List<QuestionOption> getSelectOptionList() {
		return selectOptionList;
	}

	public List<String> getAllIndexList() {
		return allIndexList;
	}
}
